package net.wanho.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.wanho.dto.PlaceExportDTO;
import net.wanho.mapper.PlaceMapper;
import net.wanho.po.Place;
import net.wanho.service.PlaceService;
import net.wanho.vo.PageInfo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 32033
 * @description 针对表【place(产地表)】的数据库操作Service实现
 * @createDate 2025-01-11 17:01:23
 */
@Service
public class PlaceServiceImpl extends ServiceImpl<PlaceMapper, Place>
        implements PlaceService {


    @Override
    public PageInfo<Place> getPlacePage(int pageNum, int pageSize, Place place) {
        Page<Place> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Place> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(!ObjectUtils.isEmpty(place.getPlaceNum()), Place::getPlaceNum, place.getPlaceNum());
        wrapper.like(!ObjectUtils.isEmpty(place.getPlaceName()), Place::getPlaceName, place.getPlaceName());
        wrapper.like(!ObjectUtils.isEmpty(place.getIntroduce()), Place::getIntroduce, place.getIntroduce());
        wrapper.like(!ObjectUtils.isEmpty(place.getIsDelete()), Place::getIsDelete, place.getIsDelete());
        this.baseMapper.selectPage(page, wrapper);

        PageInfo<Place> pageInfo = new PageInfo<>();
        pageInfo.setPageNum(page.getCurrent());
        pageInfo.setPageSize(page.getSize());
        pageInfo.setTotalNum(page.getTotal());
        pageInfo.setPageCount(page.getCurrent());
        pageInfo.setResultList(page.getRecords());
        return pageInfo;
    }

    @Override
    public Place selectOneByPlaceNum(Integer placeNum) {
        return this.baseMapper.selectOneBySupplyNum(placeNum);
    }

    @Override
    public List<Place> exportTable(PlaceExportDTO placeExportDTO) {
        Page<Place> page = new Page<>(placeExportDTO.getPageNum(), placeExportDTO.getPageSize());
        LambdaQueryWrapper<Place> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(!ObjectUtils.isEmpty(placeExportDTO.getPlaceName()), Place::getPlaceName, placeExportDTO.getPlaceName());
        wrapper.like(!ObjectUtils.isEmpty(placeExportDTO.getIntroduce()), Place::getIntroduce, placeExportDTO.getIntroduce());
        wrapper.like(!ObjectUtils.isEmpty(placeExportDTO.getPlaceNum()), Place::getPlaceNum, placeExportDTO.getPlaceNum());
        this.page(page, wrapper);

        return page.getRecords();
    }
}




